package com.qianbei.user.withdrawal;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.android.volley.Request;
import com.qianbei.R;
import com.qianbei.common.base.BaseActivity;
import com.qianbei.common.init.SetData;
import com.qianbei.common.net.control.ServerControl;
import com.qianbei.common.net.control.ServerResult;
import com.qianbei.common.net.view.MsgAlert;
import com.qianbei.common.rxbus.RxBus;

public class BindingAlipayActivity extends BaseActivity {
    private String userID;

    private EditText mEtBindName;
    private EditText mEtBindNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_binding_alipay);

        setTitle("绑定支付宝");
        mTitle.setrightTitle("完成");

        userID = SetData.getUserID();
        mEtBindName = (EditText) findViewById(R.id.et_bind_name);
        mEtBindNumber = (EditText) findViewById(R.id.et_bind_number);

    }

    private void initGetData(String bindName, String bindNumber) {
        ServerControl sc = new ServerControl(Request.Method.POST, BINDING_ALIPAY,
                "uid", userID,
                "name", bindName,
                "username", bindNumber);
        sc.serverListener = new ServerControl.ServerListener() {

            @Override
            public void serverFinish(ServerResult sr) {
                if (sr.isContinue) {
                    new MsgAlert().show(sr.bodyData.optString("msg"));

                    if (getIntent() != null && getIntent().getStringExtra("task").equals("")) {
                        RxBus.getDefault().post("getUserInfo");

                    }
                    Intent intent = new Intent();
                    setResult(222, intent);
                    finish();
                }
            }
        };
        sc.startVolley();
    }

    @Override
    public void fClick(int id) {
        super.fClick(id);
        switch (id) {
            case R.id.tv_right:
                String bindName = mEtBindName.getText().toString();
                String bindNumber = mEtBindNumber.getText().toString();
                if (TextUtils.isEmpty(bindName)) {
                    new MsgAlert().show("请填写支付宝姓名");
                } else if (TextUtils.isEmpty(bindNumber)) {
                    new MsgAlert().show("请填写支付宝账号");
                } else {
                    initGetData(bindName, bindNumber);
                }
                break;
        }
    }
}
